# main world
struct world_main : dd_world {

	# test sprite
	struct dd_sprite my_sprite;

	# bezier curve points
	struct dd_vector2d bezier1;
	struct dd_vector2d bezier2;
	struct dd_vector2d bezier3;

	# bezier counter
	int counter;

	# current point ( 0 = top left, 1 = top right, 2 = bottom right, 3 = bottom left )
	int point;

	# init sprite
	void init() {

		# start from point 0
		this.point = 0;
		this.counter = 100;

		# first bezier curve has random values
		this.bezier1.x = 0;
		this.bezier1.y = 0;
		this.bezier2.x = DD_GAME_WIDTH -10;
		this.bezier2.y = 0;
		this.bezier3.x = DD_GAME_WIDTH;
		this.bezier3.y = DD_GAME_HEIGHT;

		# first sprite is at the top
		this.my_sprite.name = "dd_logo.png";
		this.my_sprite.x = 0;
		this.my_sprite.y = 0;
		this.my_sprite.load();

	};

	# update sprite's position
	override void update() {

		# update counter
		this.counter = this.counter +1;

		# counter finished, moved to next curve
		if (this.counter > 100) {

			# reset counter and move to next point
			this.counter = 0;
			this.point = this.point +1;
			if (this.point >= 4) {
				this.point = 0;
			}

			# calculate the first two points of a bezier curve
			this.bezier1.x = this.my_sprite.x +this.my_sprite.w/2;
			this.bezier1.y = this.my_sprite.y +this.my_sprite.h/2;

			# the third point depends on the active point
			if (this.point == 0) {
				this.bezier3.x = 0;
				this.bezier3.y = 0;
			}

			if (this.point == 1) {
				this.bezier3.x = DD_GAME_WIDTH;
				this.bezier3.y = 0;
			}

			if (this.point == 2) {
				this.bezier3.x = DD_GAME_WIDTH;
				this.bezier3.y = DD_GAME_HEIGHT;
			}

			if (this.point == 3) {
				this.bezier3.x = 0;
				this.bezier3.y = DD_GAME_HEIGHT;
			}

			int halfNewx;
			int halfNewy;
			halfNewx = this.bezier1.x +(this.bezier3.x -this.bezier1.x) /2;
			halfNewy = this.bezier1.y +(this.bezier3.y -this.bezier1.y) /2;
			this.bezier2.x = halfNewx +(this.bezier2.x -halfNewx) /2;
			this.bezier2.y = halfNewy +(this.bezier2.y -halfNewy) /2;

		} # counter finished

		# calculate the interpolation of the first 2 points (1 and 2)
		int half1x;
		half1x = this.bezier1.x +(this.bezier2.x -this.bezier1.x) *this.counter /100;

		int half1y;
		half1y = this.bezier1.y +(this.bezier2.y -this.bezier1.y) *this.counter /100;

		# calculate the interpolation of the next 2 points (2 and 3)
		int half2x;
		half2x = this.bezier2.x +(this.bezier3.x -this.bezier2.x) *this.counter /100;

		int half2y;
		half2y = this.bezier2.y +(this.bezier3.y -this.bezier2.y) *this.counter /100;

		# calculate the interpolation of those points
		int finalx;
		finalx = half1x +(half2x -half1x) *this.counter /100;

		int finaly;
		finaly = half1y +(half2y -half1y) *this.counter /100;

		# apply result to sprite
		this.my_sprite.x = finalx -this.my_sprite.w/2;
		this.my_sprite.y = finaly -this.my_sprite.h/2;

	}; # update

	# draw sprite
	override void draw() {
		this.my_sprite.draw();
	};

	override void click() {
		this.counter = 100;
	};

}; # world_main
